home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / info-sys / www / tkhtml-2.3 / tkhtml-2 / tkHTML-2.3 / tix / Utils.tcl < prev   
Encoding:
Text File  |  1995-02-12  |  3.9 KB  |  155 lines

  1. #----------------------------------------------------------------------
  2. #
  3. #
  4. #           Package loading
  5. #
  6. #
  7. #----------------------------------------------------------------------
  8. proc setenv {name args} {
  9.     global env
  10.  
  11.     if {[llength $args] == 1} {
  12.         return [set env($name) [lindex $args 0]]
  13.     } else {
  14.         if {[info exists env($ename)] == 0} {
  15.             tkerror "Error in setenv: "
  16.                     "environment variable \"$name\" does not exist"
  17.         } else {
  18.             return $env($name)
  19.         }
  20.     }
  21. }
  22. #----------------------------------------------------------------------
  23. #
  24. #
  25. #           Handling options in a command
  26. #
  27. #
  28. #----------------------------------------------------------------------
  29. proc tixHandleOptions {record validOptions arglist} {
  30.     upvar $record data
  31.  
  32.     set len [expr [llength $arglist]-2 ]
  33.     set i 0
  34.  
  35.     while {$i <= $len} {
  36.     set option [lindex $arglist $i]
  37.     incr i
  38.     set arg [lindex $arglist $i]
  39.     incr i
  40.  
  41.     if {[lsearch $validOptions $option] == "-1"} {
  42.         return -code error \
  43.         "unknown option $option; must be one of $validOptions"
  44.     }
  45.     set data($option) $arg
  46.     }
  47. }
  48.  
  49.  
  50. #----------------------------------------------------------------------
  51. #
  52. #
  53. #           U T I L I T Y   F U N C T I O N S  F O R   T I X 
  54. #
  55. #
  56. #----------------------------------------------------------------------
  57.  
  58. # RESET THE STRING IN THE ENTRY
  59. proc tixSetEntry {entry string} {
  60.     set oldstate [lindex [$entry config -state] 4]
  61.     $entry config -state normal
  62.     $entry delete 0 end
  63.     $entry insert 0 $string
  64.     $entry config -state $oldstate
  65. }
  66.  
  67. # GET THE FIRST SELECTED ITEM IN A LIST
  68. proc tixListGetSingle {lst} {
  69.     set indices [$lst curselection]
  70.     if {$indices != "" } {
  71.     return [$lst get [lindex $indices 0]]
  72.     } else {
  73.     return ""
  74.     }
  75. }
  76. #-------------------------------
  77. # DISABLE EVERYTHING IN A WINDOW
  78. #-------------------------------
  79. proc tixDisableAll {w} {
  80.     foreach x [tixDescendants $w] {
  81.     catch {$x config -state disabled}
  82.     }
  83. }
  84. #------------------------------
  85. # ENSABLE EVERYTHING IN A WINDOW
  86. #------------------------------
  87. proc tixEnableAll {w} {
  88.     foreach x [tixDescendants $w] {
  89.     catch {$x config -state normal}
  90.     }
  91. }
  92. #------------------------------
  93. # RETURN EVERYTHING IN A WINDOW
  94. #------------------------------
  95. proc tixDescendants {parent} {
  96.     set des {}
  97.     lappend des $parent
  98.  
  99.     foreach w [winfo children $parent] {
  100.     foreach x [tixDescendants $w] {
  101.         lappend des $x
  102.     }
  103.     }
  104.     return $des
  105. }
  106. #----------------------------------------------------------------------
  107. # RECORD A DIALOG'S POSITION AND RESTORE IT THE NEXT TIME IT IS OPENED
  108. #----------------------------------------------------------------------
  109. proc tixDialogRestore {w {flag -geometry}} {
  110.     global tixDPos
  111.  
  112.     if [info exists tixDPos($w)] {
  113.     if ![winfo ismapped $w] {
  114.         wm geometry $w $tixDPos($w)
  115.         wm deiconify $w
  116.     }
  117.     } elseif {$flag == "-geometry"} {
  118.     update
  119.     set tixDPos($w) [winfo geometry $w]
  120.     } else {
  121.     update
  122.     set tixDPos($w) +[winfo rootx $w]+[winfo rooty $w]
  123.     }
  124. }
  125. #----------------------------------------------------------------------
  126. # RECORD A DIALOG'S POSITION AND RESTORE IT THE NEXT TIME IT IS OPENED
  127. #----------------------------------------------------------------------
  128. proc tixDialogWithdraw {w {flag -geometry}} {
  129.     global tixDPos
  130.  
  131.     if [winfo ismapped $w] {
  132.     if {$flag == "-geometry"} {
  133.         set tixDPos($w) [winfo geometry $w]
  134.     } else {
  135.         set tixDPos($w) +[winfo rootx $w]+[winfo rooty $w]
  136.     }
  137.     wm withdraw $w
  138.     }
  139. }
  140. #----------------------------------------------------------------------
  141. # RECORD A DIALOG'S POSITION AND RESTORE IT THE NEXT TIME IT IS OPENED
  142. #----------------------------------------------------------------------
  143. proc tixDialogDestroy {w {flag -geometry}} {
  144.     global tixDPos
  145.  
  146.     if [winfo ismapped $w] {
  147.     if {$flag == "-geometry"} {
  148.         set tixDPos($w) [winfo geometry $w]
  149.     } else {
  150.         set tixDPos($w) +[winfo rootx $w]+[winfo rooty $w]
  151.     }
  152.     }
  153.     destroy $w
  154. }
  155.